package org.byqh.dqeai.dto.common;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PageData<T> {
    /**
     * 当前页
     */
    private Long page = 1L;

    /**
     * 当前页数据量
     */
    private Long size = 10L;

    /**
     * 当前页记录
     */
    private List<T> records = new ArrayList<>();

    /**
     * 总页数
     */
    private Long totalPage = 0L;

    /**
     * 总数据量
     */
    private Long totalCount = 0L;

    public PageData() {
    }

    public PageData(Long page, Long size, List<T> records, Long totalPage, Long totalCount) {
        this.page = page;
        this.size = size;
        this.records = records;
        this.totalPage = totalPage;
        this.totalCount = totalCount;
    }

    public PageData(IPage<T> data) {
        if (data != null) {
            this.page = data.getCurrent();
            this.size = data.getSize();
            this.records = data.getRecords();
            this.totalCount = data.getTotal();
            this.totalPage = data.getPages();
        }
    }
}
